############ REPLICATION FILE FOR SEEING WHAT CITIZENS MISS ############

# Load packages -----------------------------------------------------------

rm(list=ls())
library(tidyverse)
library(knitr)
library(stargazer)
library(magrittr)
library(memor)
library(readxl)
library(broom)
library(vtable)
library(lfe)
library(pastecs)
library(xtable)
library(Hmisc)
library(corrplot)
library(xtable)
library(conflicted)
library(acledR) # to download ACLED data


conflicted::conflict_prefer("select", "dplyr")
conflicted::conflicts_prefer(dplyr::filter)
conflicted::conflict_prefer("corrplot", "corrplot")
conflicted::conflicts_prefer(dplyr::summarize)

# Load data ---------------------------------------------------------------

location_lvl<-read_csv("location_lvl_data.csv") #Data aggregated to location level from supervisor surveys, GPS coordinates of locations

df<-read_csv("main_final.csv") #Main dataset for analysis 

## Monitors Data
monitors<-read_csv("Monitors_endline.csv") # Monitors data merged baseline and reporting data
monitors_baseline<-read.csv("Monitors_Baseline.csv") # Monitors baseline demographics data

## Citizens_data
citizens.bl<-read.csv("Citizens_Baseline.csv") # citizens baseline data

## Map and ACLED data

# details on how to use the ACLED API here: https://cran.r-project.org/web/packages/acledR/index.html; requires a username and password to be inputted below 
ACLED<-acled_api(email = ,#your email
          password = , # your password
          country = "Ivory Coast",
          start_date="2020-10-31", 
          end_date="2020-12-31")


civ.df<-read.csv("civ_df.csv", encoding = "utf-8") #shape file for Côte d'Ivoire map (encoding important to deal with accented locations)

centroids<-read.csv("civ_dept_centroids.csv") # this is just the centroid of each department for labeling purposes



# Figure 1 ----------------------------------------------------------------

carnegie_cases<-c("Abengourou","Bouaké", "Daloa", "Gagnoa", "Korhogo", "Man", "San-Pedro", "Yamoussoukro")
carnegie_cases2<-c("Abengourou","Bouake", "Daloa", "Gagnoa", "Korhogo", "Man", "San Pedro", "Yamoussoukro", "Abidjan")
acled_cases<-c("Abengourou","Bouake", "Daloa", "Gagnoa", "Korhogo", "Man", "San-Pedro", "Yamoussoukro")

civ.df$carnegie<-0
for (i in 1:length(carnegie_cases)){
  civ.df$carnegie[civ.df$NAME_3==paste(carnegie_cases[i])]<-1
}

civ.df$carnegie[civ.df$NAME_3=="Bouaké"]<-1 # make sure there is an accent aigue on the e!
civ.df$carnegie[civ.df$NAME_3=="Abidjan"]<-1


carnegie_map<-subset(civ.df, carnegie==1)

dept_centroids_carnegie<-centroids[centroids$dept_name %in% carnegie_cases2,]

ggplot(civ.df)+
  aes(x=long, y=lat) +
  geom_polygon(aes(group=group), fill=NA,  color="gray")+
  geom_point(data=location_lvl, aes(x=long, y=lat), color="black", size=.7)+
  #geom_point(data=acled,aes(x=longitude, y=latitude), color="red", size=2)+
  coord_map("mercator")+
  geom_path(data=carnegie_map, aes(x=long, y=lat, group=group), color="black", size=1)+
  geom_label(data=dept_centroids_carnegie, aes(label = dept_name, x = long, y = lat), color="black", size=3)+
  theme_bw()+theme(text = element_text(size = 20),panel.grid=element_blank(), axis.text.x=element_blank(),
                   axis.text.y=element_blank(), axis.ticks.x=element_blank(),
                   axis.ticks.y=element_blank(),
                   axis.title.x=element_blank(), axis.title.y=element_blank())


# Table 1 -----------------------------------------------------------------

vars<-c("electricity", "cellphone", "paved", "high_school", "pop1000")

sum_stats<-t(stat.desc(location_lvl[vars]))  

sum_stats<-as.data.frame(sum_stats[,c("mean", "min", "max", "std.dev", "nbr.val")]) 

t1<- sum_stats %>% mutate_if(is.numeric, round, 2)

# Table 2 -----------------------------------------------------------------


# here we aggregate to the location level from the citizen baseline to check balance across treatment conditions
vars2<-c("female", "news_consumer", "vote_gov", "muslim", "edu2", "conflict_land", 
         "conflict_money", "conflict_theft","conflict_ethnicity","conflict_religious","elections_fear",
         "fear_perso","fear_fam","fear_eth","fear_relig")

df_all<- citizens.bl %>% group_by(zone, treat_monitor) %>% summarise_at(vars2, mean, na.rm=T)

balance3<-data.frame(vars2)

for (i in 1:length(vars2)){
  tryCatch({
    balance3[i,2]<-lapply(df_all[vars2[i]], function(x) {t.test(x[df_all$treat_monitor==1], x[df_all$treat_monitor==0])$estimate[1]})
    balance3[i,3]<-lapply(df_all[vars2[i]], function(x) {t.test(x[df_all$treat_monitor==1], x[df_all$treat_monitor==0])$estimate[2]})
    balance3[i,4]<-lapply(df_all[vars2[i]], function(x) {t.test(x[df_all$treat_monitor==1], x[df_all$treat_monitor==0])$p.value})
  }, error=function(e){})
}

colnames(balance3)<-c("var", "treat", "control", "p-value")
t2<-balance3



# Table 3 -----------------------------------------------------------------


t3<-df %>% filter(date>0) %>% mutate(date=factor(date, levels=c(1, 2), labels=c("Election Day", "Post-Election")))  %>% 
  select(date, violence_any_dummy, physical_dummy, verbal_dummy, protest_dummy, election_violence_dummy) %>% 
  group_by(date) %>% summarize(across(violence_any_dummy:election_violence_dummy, ~round(mean(., na.rm=T)*100, digits=2)))




# Table 4 -----------------------------------------------------------------

reg1<-felm(violence_any_dummy~treat_all | date | 0 | zone, data=df)
reg2<-felm(c_violence_any_dummy~treat_all | date | 0 | zone, data=df)
reg3<-felm(m_violence_any_dummy~treat_all | date | 0 | zone, data=df)

stargazer(reg1, reg2, reg3,type="text",
          no.space = T,
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Any violence reported"),
          dep.var.labels = c("All reporters", "Citizens", "Monitors"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of monitor treatment on reports of any violence",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")

# Table 5 -----------------------------------------------------------------

r4<-felm(any_firsthand~treat_all |date |0 | zone, data=df)
r5<-felm(any_verbal_witness~treat_all |date| 0 | zone, data=df)
r6<-felm(any_physical_witness~treat_all |date | 0 | zone, data=df)
r7<-felm(any_protest_witness~treat_all |date |0 | zone, data=df)


stargazer(r4, r5, r6, r7, no.space = T, type="text",
         column.sep.width = "1pt",  font.size = "small",
         covariate.labels = "Citizen + Monitor",
         dep.var.labels = c("Any violence", "Verbal", "Physical", "Protest"),
         header=FALSE,
         title = "Effect of citizen + monitor treatment on firsthand reports of violence",
         star.char=c("+", "*", "**", "***"),
         star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
         notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
         notes.append = F, notes.align = "r")


# Figure 3 ----------------------------------------------------------------



correlate<-df %>% ungroup %>% select(protest_monitor_dummy, verbal_monitor_dummy, physical_monitor_dummy, contains("witness_citizen")) %>%
  rename("monitor\nprotest"=protest_monitor_dummy,
         "monitor\nverbal"=verbal_monitor_dummy,
         "monitor\nphysical"=physical_monitor_dummy,
         "citizen\nfirsthand\nprotest"=protest_witness_citizen,
         "citizen\nfirsthand\nverbal"=verbal_witness_citizen,
         "citizen\nfirsthand\nphysical"=physical_witness_citizen)

res<-rcorr(as.matrix(correlate))

alpha_col <- function(colors, alpha = 0.5) {
  rgbcolors <- col2rgb(colors, alpha = TRUE)
  rgbcolors["alpha", ] <- alpha * 255
  apply(rgbcolors, 2, function(x) rgb(x[1], x[2], x[3], x[4], maxColorValue = 255))
}

corrplot(res$r, 
          order = "alphabet", 
          p.mat = res$P, 
          insig = "blank", 
          method = "color", 
          diag = FALSE, 
          tl.col = "black", 
          addgrid.col = 'white',
          col = alpha_col(colorRampPalette(c("gray","black"))(200))) %>%
  
  
  corrRect(namesMat = c("citizen\nfirsthand\nverbal",
                        "monitor\nverbal",
                        "citizen\nfirsthand\nphysical",
                        "monitor\nphysical"), lwd =5) %>%
  
  corrRect(namesMat = c("monitor\nphysical",
                        "citizen\nfirsthand\nphysical",
                        "monitor\nverbal",
                        "citizen\nfirsthand\nverbal"),
           lwd = 5)



# Table 6  -----------------------------------------------------------------

experience<-c("prior_exp2", "N_DeptWork2")
experience2<-c("Previously monitored election violence", "Number of departments worked previously")


Tab6<-lapply(monitors[experience], function(x){tidy(felm(violence_any_monitor~x|date | 0 | zone, data=monitors))}) %>% bind_rows() %>% mutate(term=experience2)



# Table 7 -----------------------------------------------------------------


distance<-c("distance_far", "distance_traveled")
distance2<-c("Traveled farther than 10km to monitor", "Distance traveled categorical variable")

tab7<-lapply(monitors[distance], function(x){tidy(felm(violence_any_monitor~x|date | 0 | zone, data=monitors))}) %>% bind_rows() %>% mutate(term=distance2)


########### APPENDIX TABLES ##################


# Table A1 Sum Stats Citizens -----------------------------------------------

dem<-c("rural","leader", "female", "age", 
       "asset_index", "water", "cash","food", "meds", "edu", "vote2015", "vote_plan",
       "vote_gov", "pid_opp","no_pid_no_vote", "news_radio", "news_tv", 
       "news_newspaper", "news_socialmedia", "news_internet", 
       "protest", "verbal", "physical","killings", "damage", "violence_index",  
       "unemployed", "akan", "krou", "nmande", "smande", 
       "voltaique", "no_ethnicity","muslim")


dem.var<-c("rural","leader", "female", "age", 
           "asset_index", "gone w/o water", "gone w/o cash","gone w/o food", "gone w/o meds", "education ", "vote 2015", "plan to vote 2020",
           "Vote ADO", "Opposition PID","No PID, no vote choice", "news from radio", "news from TV", 
           "news from paper", "news from social media", "news from internet", 
           "witnessed protest", "witnessed verbal harass", "witnessed physical violence","witnessed killings", "witnessed damage", "violence index",  
           "unemployed", "akan", "krou", "nmande", "smande", 
           "voltaique", "no ethnicity","muslim")

summary_stats<-t(stat.desc(citizens.bl[dem]))

summary_stats<-as.data.frame(summary_stats[,c("mean", "min", "max", "std.dev", "nbr.val")])
summary_stats$desc<-dem.var
summary_stats<-summary_stats[c(6,1,2,3,4,5)]
colnames(summary_stats)<-c("description", "mean", "min", "max", "std.dev", "n")
tabA1<-summary_stats

# Table A2 Sum Stats Monitors -----------------------------------------------
dem.m<-c("rural", "female", "age", 
       "asset_index", "water", "cash","food", "meds", "edu", "vote2015", "vote_plan",
       "vote_gov", "pid_opp","no_pid_no_vote", "news_radio", "news_tv", 
       "news_newspaper", "news_socialmedia", "news_internet", 
       "protest", "verbal", "physical","killings", "damage", "violence_index",  
       "unemployed", "akan", "krou", "nmande", "smande", 
       "voltaique", "no_ethnicity","muslim")


dem.var.m<-c("rural","female", "age", 
           "asset_index", "gone w/o water", "gone w/o cash","gone w/o food", "gone w/o meds", "education ", "vote 2015", "plan to vote 2020",
           "Vote ADO", "Opposition PID","No PID, no vote choice", "news from radio", "news from TV", 
           "news from paper", "news from social media", "news from internet", 
           "witnessed protest", "witnessed verbal harass", "witnessed physical violence","witnessed killings", "witnessed damage", "violence index",  
           "unemployed", "akan", "krou", "nmande", "smande", 
           "voltaique", "no ethnicity","muslim")


summary_stats.m<-t(stat.desc(monitors_baseline[dem.m]))

#mean, min, max, std.dev, nbr.val

summary_stats.m<-as.data.frame(summary_stats.m[,c("mean", "min", "max", "std.dev", "nbr.val")])
summary_stats.m$desc<-dem.var.m
summary_stats.m<-summary_stats.m[c(6,1,2,3,4,5)]
colnames(summary_stats.m)<-c("description", "mean", "min", "max", "std.dev", "n")

tabA2<-summary_stats.m


# Table A3 Sum Stats Monitor specific -----------------------------------------------

m.only<-c("live_assign", "work_close", "prior_exp2", "N_DeptWork", 
         c(colnames(monitors_baseline)[grepl("pref_monitor",colnames(monitors_baseline))]),
         "violence_ethnic_het", "violence_ethnic_homo"
         , "violence_partis_opp", "violence_partis_govt", "violence_partis_comp", "violence_rural", "violence_urban")
m.only2<-c("Live in dept assigned","Monitor within 10km of home", "Previously monitored", 
          "Count depts worked previously", 
          "Exp: Urban", "Exp: villages on main road", "Exp: far-flung villages", "Exp: good network", "Exp: relationships", "Exp: Never visited",
          "+ Violence in het. ethnic places",
          "+ Violence in homo. ethnic places",
          "+ Violence in opp strongholds",
          "+ Violence in govt strongholds",
          "+ Violence in electorally competitive",
          "+ Violence in rural settings",
          "+ Violence in urban settings")

summary_stats_m_only<-t(stat.desc(monitors_baseline[m.only]))


summary_stats_m_only<-as.data.frame(summary_stats_m_only[,c("mean", "min", "max", "std.dev", "nbr.val")])
summary_stats_m_only$desc<-m.only2

summary_stats_m_only<-summary_stats_m_only[c(6,1,2,3,4,5)]
colnames(summary_stats_m_only)<-c("description", "mean", "min", "max", "std.dev", "n")
tabA3<-summary_stats_m_only

# Table A4 - correlation matrix table ----------------------------------------------------------------


tabA4<-cor(correlate)


# Figure A1 - correlation matrix reporting by citizens/monitors ---------------------------------------------------------------

correlate<-df %>% ungroup %>% select(violence_any_citizen, protest_citizen_dummy, verbal_citizen_dummy, 
                                     physical_citizen_dummy, election_violence_citizen_dummy, violence_any_monitor, 
                                     protest_monitor_dummy, verbal_monitor_dummy, physical_monitor_dummy, election_violence_monitor_dummy) %>% 
  rename("citizen_violence"=violence_any_citizen,
         "citizen_protest"=protest_citizen_dummy,
         "citizen_verbal"=verbal_citizen_dummy,
         "citizen_physical"=physical_citizen_dummy,
         "citizen_electoral"=election_violence_citizen_dummy,
         "monitor_violence"=violence_any_monitor,
         "monitor_protest"=protest_monitor_dummy,
         "monitor_verbal"=verbal_monitor_dummy,
         "monitor_physical"=physical_monitor_dummy,
         "monitor_electoral"=election_violence_monitor_dummy)
corrplot(res$r, order="alphabet", p.mat = res$P, insig = "blank")



# Table A5 effect of monitor treatment on reports of no violence ----------------------------------------------------------------

reg0<-felm(cit_0~treat_all |date | 0 | zone, data=df) 
stargazer(reg0, type="text",
          no.space = T,
          column.sep.width = "1pt",  font.size = "small",
          #dep.var.caption = c("Reports of No violence"),
          dep.var.labels = c("Reports of no violence"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of monitor treatment on reports of no violence",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A6 effect of monitor treatment on reports of any violence  ----------------------------------------------------------------

reg1p<-lm(violence_any_dummy~treat_all, data=df)
reg2p<-lm(c_violence_any_dummy~treat_all, data=df)
reg3p<-lm(m_violence_any_dummy~treat_all, data=df)

stargazer(reg1p, reg2p, reg3p, type="text",
          no.space = T,
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Any violence reported"),
          dep.var.labels = c("All reporters", "Citizens", "Monitors"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of monitor treatment on reports of any violence",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A7 Effect of citizen + monitor treatment on firsthand reports of violence ----------------------------------------------------------------

reg4p<-felm(any_firsthand~treat_all |0 |0 | zone, data=df)
reg5p<-felm(any_verbal_witness~treat_all |0| 0 | zone, data=df)
reg6p<-felm(any_physical_witness~treat_all |0 | 0 | zone, data=df)
reg7p<-felm(any_protest_witness~treat_all |0 |0 | zone, data=df)

stargazer(reg4p, reg5p, reg6p, reg7p, no.space = T, type="text",
          column.sep.width = "1pt",  font.size = "small",
          covariate.labels = "Crowdseed + Monitor",
          dep.var.labels = c("Any violence", "Verbal", "Physical", "Protest"),
          header=FALSE,
          title = "Effect of citizen + monitor treatment on firsthand reports of violence",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A8 Effect of citizen + monitor treatment on any violence reported by all reporters ---------------------------------------------------------------


reg8<-felm(total_reports~treat_all |date | 0 | zone, data=df)
reg9<-felm(violence_any_dummy~treat_all | date | 0 | zone, data=df)
reg10<-felm(violence_any_share~treat_all | date | 0| zone, data=df)

stargazer(reg8, reg9, reg10,type="text",
          no.space = T,
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Any violence reported"),
          dep.var.labels = c("count", "binary", "share"),
          covariate.labels = "Crowdseed + Monitor",
          header=FALSE, title = "Effect of crowdseed + monitor treatment on any violence reported by all reporters",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A9 Effect of citizen + monitor treatment on any violence reported by citizens---------------------------------------------------------------


reg11<-felm(total_citizen~treat_all |date | 0 | zone, data=df)
reg12<-felm(c_violence_any_dummy~treat_all | date | 0 | zone, data=df)
reg13<-felm(c_violence_any_share~treat_all | date | 0| zone, data=df)
stargazer(reg11, reg12, reg13,type="text",
          no.space = T,
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Any violence reported"),
          #dep.var.labels = c("count", "binary", "share"),
          covariate.labels = "Crowdseed + Monitor",
          header=FALSE, title = "Effect of crowdseed + monitor treatment on any violence reported by citizens",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001"), 
          notes.append = F, notes.align = "r")


# Table A10 Effect of citizen + monitor treatment on any violence reported by monitors---------------------------------------------------------------


reg14<-felm(total_monitor~treat_all |date | 0 | zone, data=df)
reg15<-felm(m_violence_any_dummy~treat_all | date | 0 | zone, data=df)
reg16<-felm(m_violence_any_share~treat_all | date | 0| zone, data=df)

stargazer(reg14, reg15, reg16,type="text",
          no.space = T,
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Any violence reported"),
          dep.var.labels = c("count", "binary", "share"),
          covariate.labels = "Crowdseed + Monitor",
          header=FALSE, title = "Effect of crowdseed + monitor treatment on any violence reported by monitors",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001"), 
          notes.append = F, notes.align = "r")


# Table A11 Effect of citizen + monitor treatment on reports of physical violence---------------------------------------------------------------


reg3<-felm(physical_dummy~treat_all | date | 0 | zone, data=df)
c_reg3<-felm(physical_citizen_dummy~treat_all | date | 0 | zone, data=df)
m_reg3<-felm(physical_monitor_dummy~treat_all | date | 0 | zone, data=df)

stargazer(reg3, c_reg3, m_reg3, type="text",
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Physical violence reported"),
          dep.var.labels = c("All reporters", "Citizens", "Monitors"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of citizen + monitor treatment on reports of physical violence",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A12 Effect of citizen + monitor treatment on reports of verbal harassment---------------------------------------------------------------

reg2<-felm(verbal_dummy~treat_all | date | 0 | zone, data=df)
c_reg2<-felm(verbal_citizen_dummy~treat_all |date| 0 | zone, data=df)
m_reg2<-felm(verbal_monitor_dummy~treat_all |date| 0 | zone, data=df)

stargazer(reg2, c_reg2, m_reg2, type="text",
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Verbal harassment reported"),
          dep.var.labels = c("All reporters", "Citizens", "Monitors"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of citizen + monitor treatment on reports of verbal harassmanet",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A13 Effect of citizen + monitor treatment on reports of protest---------------------------------------------------------------

reg1<-felm(protest_dummy~treat_all |date| 0 | zone, data=df)
c_reg1<-felm(protest_citizen_dummy~treat_all |date| 0 | zone, data=df)
m_reg1<-felm(protest_monitor_dummy~treat_all |date| 0 | zone, data=df)

stargazer(reg1, c_reg1, m_reg1, type="text",
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Protest reported"),
          dep.var.labels = c("All reporters", "Citizens", "Monitors"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of citizen + monitor treatment on reports of protest",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Table A14 Effect of citizen + monitor treatment on reports of election-related violence---------------------------------------------------------------


reg4<-felm(election_violence_dummy~treat_all | date | 0 | zone, data=df)
c_reg4<-felm(election_violence_citizen_dummy~treat_all | date | 0 | zone, data=df)
m_reg4<-felm(election_violence_monitor_dummy~treat_all | date | 0 | zone, data=df)

stargazer(reg4, c_reg4, m_reg4, type="text",
          column.sep.width = "1pt",  font.size = "small",
          dep.var.caption = c("Election-related violence reported"),
          dep.var.labels = c("All reporters", "Citizens", "Monitors"),
          covariate.labels = "Monitor",
          header=FALSE, title = "Effect of citizen + monitor treatment on reports of election-related violence",
          star.char=c("+", "*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
          notes=c("+ p$<$0.1; * p$<$0.05; ** p$<$0.01; *** p$<$0.001"), 
          notes.append = F, notes.align = "r")


# Figure A3 Physical violence reported in sampled locations ---------------------------------------------------------------

# subset acled data to our departments


ACLED2<-ACLED %>% filter(admin3 %in% acled_cases)

ggplot(civ.df)+
  aes(x=long, y=lat) +
  geom_polygon(aes(group=group), fill=NA,  color="black")+
  geom_point(location_lvl, mapping=aes(x=long, y=lat, shape=factor(any_physical2)), size=2)+
    geom_point(data=ACLED2,aes(x=as.numeric(longitude), y=as.numeric(latitude)), color="red", size=2)+
coord_map("mercator")+
  scale_shape_manual(values=c(15,0),name="Violence in our sampled villages")+
  #geom_text(data=dept_centroids_carnegie, aes(label = dept_name, x = long, y = lat), color="black", size=3)+
  geom_path(data=carnegie_map, aes(x=long, y=lat, group=group), color="black", size=1)+
  theme_bw()+theme(text = element_text(size = 20),panel.grid=element_blank(), axis.text.x=element_blank(),
                   axis.text.y=element_blank(), axis.ticks.x=element_blank(),
                   axis.ticks.y=element_blank(),
                   axis.title.x=element_blank(), axis.title.y=element_blank())


# Table A15 Number of locations where protests were reported on election day ---------------------------------------------------------------

data_compare_acled<-df %>% filter(date==1) %>% select(zone, protest, dept) %>% 
  mutate("dept"=case_when(dept=="ABOBO" | dept=="YOPOUGON"~"ABIDJAN", TRUE~dept)) %>% 
  mutate(protest_any=case_when(protest>0~1, TRUE~0)) %>% group_by(dept) %>% 
  summarize("Locations reporting protest"=sum(protest_any, na.rm=T)) %>% mutate(dept=str_to_sentence(dept))

eday<-ACLED%>% 
  filter(admin3 %in% acled_cases) %>% filter(grepl("10-31", event_date)) %>% group_by(admin3) %>% 
  summarize("ACLED Reports Violent Demonstrations"=n())  %>% rename("dept"="admin3") 
  

acled_compare<-left_join(data_compare_acled, eday) %>% 
  mutate(`ACLED Reports Violent Demonstrations`=replace_na(`ACLED Reports Violent Demonstrations`, 0))

tabA18<-acled_compare

